package com.dilidili.controller;

import com.dilidili.service.SendSms;
import com.dilidili.utils.Random;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

@RestController
//@CrossOrigin //跨域支持
public class SmsApiController {
    @Resource
    private SendSms sendSms;


    @RequestMapping("/send")
    public Map<String,Object> code(String phone) {
        //调用封装好的随机数
        String code= Random.getCode();
        System.out.println(code);
        //蒋随机数储存到map集合中
        Map<String, Object> param = new HashMap<>();
        param.put("code", code);
        if (phone!=null&&phone!=""){
            //将集合返回出去
            System.out.println(param);
            Map<String,Object> isSand = sendSms.sand(phone, param);
            return param;
        }else {
            param.put("error","手机号不能为空");
            return param;
        }
    }
}
